package com.control.qct.businesssteward.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.activity.EverydayAccountActivity;
import com.control.qct.businesssteward.base.BaseFragment;
import com.control.qct.businesssteward.utils.PopShopSelectUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 侧滑菜单--门店选择
 * Created by Administrator on 2017/12/12 0012.
 */

@SuppressLint("ValidFragment")
public class AccountSelectFragment extends BaseFragment implements PopShopSelectUtils.ICallbackStoreListener {
    @BindView(R.id.rb_day_account)
    RadioButton mRbDayAccount;//日结
    @BindView(R.id.rb_month_account)
    RadioButton mRbMonthAccount;//月结
    public @BindView(R.id.rg_account_select)
    RadioGroup mRgAccountSelect;//日结 月结选择控件
    @BindView(R.id.tv_shop_select)
    TextView mTvShopSelect;//门店选择
    @BindView(R.id.tv_cancel)
    TextView mTvCancel;
    @BindView(R.id.tv_sure)
    TextView mTvSure;

    private EverydayAccountActivity mEverydayAccountActivity;
    private ICallbackDateListener mListener;
    private int dateId = 1;
    private String mStoreId = "";
    private PopShopSelectUtils mPopShopSelectUtils;

    public AccountSelectFragment(ICallbackDateListener listener) {
        mListener = listener;
    }

    @Override
    protected View initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        return inflater.inflate(R.layout.fragment_account_select, container, false);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mEverydayAccountActivity = (EverydayAccountActivity) context;
    }

    @Override
    protected void initView(View view) {
        //设置门店数据
        mPopShopSelectUtils = new PopShopSelectUtils();
        mPopShopSelectUtils.registerListener(this, mNetProtocol, activity, 2);
        mRgAccountSelect.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.rb_day_account:
                        dateId = 1;
                        break;
                    case R.id.rb_month_account:
                        dateId = 2;
                        break;
                }
            }
        });
    }


    @OnClick({R.id.tv_shop_select, R.id.tv_cancel, R.id.tv_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_shop_select://门店筛选
                mPopShopSelectUtils.setBottomPop(mEverydayAccountActivity, R.id.fl_content, mStoreId);
                break;
            case R.id.tv_cancel://取消
                mEverydayAccountActivity.mDlMenu.closeDrawers();
                break;
            case R.id.tv_sure://确定
                mListener.callbackDateId(dateId, mStoreId);
                mEverydayAccountActivity.mDlMenu.closeDrawers();
                break;
        }
    }

    @Override
    public void onSure(String storeId, String storeName) {
        mStoreId = TextUtils.isEmpty(storeId) ? "" : storeId;
        mTvShopSelect.setText(TextUtils.isEmpty(storeName) ? "门店" : storeName);
    }

    public interface ICallbackDateListener {
        void callbackDateId(int id, String storeId);
    }
}
